import { createApp } from 'vue'

import Cookies from 'js-cookie'

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/dark/css-vars.css'
import locale from 'element-plus/es/locale/lang/zh-cn'

import '@/assets/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'
import directive from './directive' // directive

// 注册指令
import plugins from './plugins' // plugins
import { download } from '@/utils/request'

// svg图标
import 'virtual:svg-icons-register'
import SvgIcon from '@/components/SvgIcon'
import elementIcons from '@/components/SvgIcon/svgicon'

import './permission' // permission control

import { useDict } from '@/utils/dict'
import { getConfigValue } from "@/api/sys/config"
import { parseTime, resetForm, addDateRange, handleTree, selectDictLabel, selectDictLabels, initOptions, formatOptions, startRefresh, stopRefresh } from '@/utils/base'

// 字典标签组件
import YDictTag from '@/components/YDictTag'
// 分页组件
import YPagination from '@/components/YPagination'
// 自定义表格工具组件
import YRightToolbar from '@/components/YRightToolbar'
// 图片上传组件
import YImageUpload from "@/components/YImageUpload"
// 图片预览组件
import YImagePreview from "@/components/YImagePreview"
// 文件导入组件
import YImport from "@/components/YImport"
// 文件导出组件
import YExport from "@/components/YExport"
// 文件上传组件
import YFileUpload from "@/components/YFileUpload"
// 文本编辑器组件
import YEditor from "@/components/YEditor"
// 自定义树选择组件
import YTreeSelect from '@/components/YTreeSelect'
// 历史信息展示组件
import YHistoryToolbar from "@/components/YHistoryToolbar"
// 对话框组件
import YDialog from "@/components/YDialog"
// 选择框组件
import YSelect from "@/components/YSelect"
// Radio按钮组件
import YRadio from "@/components/YRadio"
// 代码编辑器组件
import YCodeEditor from "@/components/YCodeEditor"
// 内容比对组件
import YDiffEditor from "@/components/YDiffEditor"
// 拓扑编辑器组件
import YTopoEditor from "@/components/YTopoEditor"
// 动态编辑标签
import YTag from "@/components/YTag"
// 思维导图组件
import YMind from "@/components/YMind"
// 基础饼图组件
import YBasicPieChart from "@/components/YBasicPieChart"
// 基础柱状图组件
import YBasicBarChart from "@/components/YBasicBarChart"



const app = createApp(App)

// 全局方法挂载
app.config.globalProperties.useDict = useDict
app.config.globalProperties.download = download
app.config.globalProperties.parseTime = parseTime
app.config.globalProperties.resetForm = resetForm
app.config.globalProperties.handleTree = handleTree
app.config.globalProperties.addDateRange = addDateRange
app.config.globalProperties.getConfigValue = getConfigValue
app.config.globalProperties.selectDictLabel = selectDictLabel
app.config.globalProperties.selectDictLabels = selectDictLabels
app.config.globalProperties.initOptions = initOptions
app.config.globalProperties.formatOptions = formatOptions
app.config.globalProperties.startRefresh = startRefresh
app.config.globalProperties.stopRefresh = stopRefresh

// 全局组件挂载
app.component('YDictTag', YDictTag)
app.component('YPagination', YPagination)
app.component('YImageUpload', YImageUpload)
app.component('YImagePreview', YImagePreview)
app.component('YRightToolbar', YRightToolbar)
app.component('YImport', YImport)
app.component('YExport', YExport)
app.component('YFileUpload', YFileUpload)
app.component('YEditor', YEditor)
app.component('YTreeSelect', YTreeSelect)
app.component('YHistoryToolbar', YHistoryToolbar)
app.component('YDialog', YDialog)
app.component('YSelect', YSelect)
app.component('YRadio', YRadio)
app.component('YCodeEditor', YCodeEditor)
app.component('YDiffEditor', YDiffEditor)
app.component('YTopoEditor', YTopoEditor)
app.component('YTag', YTag)
app.component('YMind', YMind)
app.component('YBasicPieChart', YBasicPieChart)
app.component('YBasicBarChart', YBasicBarChart)

app.use(router)
app.use(store)
app.use(plugins)
app.use(elementIcons)
app.component('svg-icon', SvgIcon)

directive(app)

// 使用element-plus 并且设置全局的大小
app.use(ElementPlus, {
  locale: locale,
  // 支持 large、default、small
  size: Cookies.get('size') || 'default'
})

app.mount('#app')
